package cn.tedu.hospital.settlement.service.serviceImp;

import cn.tedu.hospital.settlement.mapper.ExpenseSettlementMapper;
import cn.tedu.hospital.settlement.pojo.dto.SelectParam;
import cn.tedu.hospital.settlement.pojo.dto.SettlementSelect;
import cn.tedu.hospital.settlement.pojo.vo.SettlementVO;
import cn.tedu.hospital.settlement.service.ExpenseSettlementService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Slf4j
@Service
public class  ExpenseSettlementServiceImp implements ExpenseSettlementService {
    @Autowired
    ExpenseSettlementMapper expenseSettlementMapper;
    @Override
    public List<SettlementVO> select(SettlementSelect settlementSelect) {
        log.debug("开始执行【查询结算信息】的业务层方法{}",settlementSelect);
        SelectParam selectParam = new SelectParam();
        selectParam.setAdmissionTime(settlementSelect.getAdmissionTime());
        if (settlementSelect.getDepartmentName()!=null){
            Long departmentId = expenseSettlementMapper.selectDepartmentId(settlementSelect.getDepartmentName());
            selectParam.setDepartmentId(departmentId);
        }
        List<Long> id = new ArrayList<>();
        if (settlementSelect.getName() != null){
           id= expenseSettlementMapper.selectPatientId(settlementSelect.getName());

        }
        List<SettlementVO> list = new ArrayList<>();
        if (id.size()!=0){
            for (Long aLong : id){
                selectParam.setPatientId(aLong);
                List<SettlementVO> vo = expenseSettlementMapper.select(selectParam);
                if (vo.size()!=0){
                    list.add(vo.get(0));
                }
            }
        }
        else{
            list = expenseSettlementMapper.select(selectParam);
        }


        return list;
    }
}
